package smallChanges.Tokenization;

import java.util.Comparator;
import java.util.TreeSet;

public class TokenMappingResultSet extends TreeSet<TokenMappingEntry> {
    private static final long serialVersionUID = 1L;

    TreeSet<TokenMappingEntry> rightSorted = new TreeSet<TokenMappingEntry> (new Comparator<TokenMappingEntry>(){

        public int compare(TokenMappingEntry leftObj, TokenMappingEntry rightObj)
        {
            int result = 0;
            
            SCToken left,right;
            
            left =  leftObj.getLeftToken();
            right = rightObj.getLeftToken();
            
            result = right.getBeginColumn() - left.getBeginColumn(); 
            if( result == 0 )
            {
                result = right.getEndColumn() - left.getEndColumn(); 
            }
            return result;        
        }
    });

    //add
    public boolean add(TokenMappingEntry obj)
    {
        rightSorted.add(obj);

        return super.add(obj);
    }

    //addAll
    @SuppressWarnings("unchecked")
    public boolean addAll(java.util.Collection obj)
    {
        rightSorted.addAll(obj);

        return super.addAll(obj);
    }


    //clear
    public void clear()
    {
        rightSorted.clear();
        super.clear();
    }

    //remove
    public boolean remove(TokenMappingEntry obj)
    {
        rightSorted.remove(obj);

        return super.remove(obj);
    }

    /* add the following */
    //rightSortedFirst
    public TokenMappingEntry rightSortedFirst()
    {
        return rightSorted.first();
    }

    //rightSortedHeadSet
    public java.util.SortedSet<TokenMappingEntry> rightSortedHeadSet(TokenMappingEntry toElement)
    {
        return rightSorted.headSet(toElement);
    }

    //rightSortedIterator
    public java.util.Iterator<TokenMappingEntry> rightSortediterator()
    {
        return rightSorted.iterator();
    }

    //rightSortedLast
    public TokenMappingEntry rightSortedLast()
    {
        return rightSorted.last();
    }

    //rightSortedSubSet
    public java.util.SortedSet<TokenMappingEntry> rightSortedSubSet(TokenMappingEntry fromElement, TokenMappingEntry toElement)
    {
        return rightSorted.subSet(fromElement, toElement);
    }

    //rightSortedTailSet
    public java.util.SortedSet<TokenMappingEntry> rightSortedTailSet(TokenMappingEntry fromElement)
    {
        return rightSorted.tailSet(fromElement);
    }

}
